package ch.zbw.pra.sysventory.dataaccess.dataAccessObject;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;

import ch.zbw.pra.sysventory.database.jdbcTemplate.PrinterJDBCTemplate;
import ch.zbw.pra.sysventory.model.Printer;
import ch.zbw.pra.sysventory.utils.DatabaseUtils;

/**
 * Bereitet Daten für den Zugriff auf die Datenbank im DatabaseLayer auf
 * 
 * @author Ralph Koster & Roberto Lucas
 */

public class PrinterDataAccessObject implements Serializable {

	private static final long serialVersionUID = 8387995733716431036L;
	private ApplicationContext context;
	private PrinterJDBCTemplate printerJDBCTemplate;

	public PrinterDataAccessObject() {
		context = DatabaseUtils.getContext();
		printerJDBCTemplate = (PrinterJDBCTemplate)context.getBean("printer");
	}

	public List<Printer> getAllPrinterFromDatabase() {
		List<Printer> printers = printerJDBCTemplate.listPrinters();
		return printers;
	}

	public List<Printer> getAllPrinterFromComputer(Integer computerId) {
		List<Printer> printers = printerJDBCTemplate.listAllPrintersFromComputer(computerId);
		return printers;
	}

	public void writePrintersToDatabase(List<Printer> printers, Integer computerId){
			for(Printer printer:printers){
				printerJDBCTemplate.insertPrinter(printer, computerId);
			}
		}

}
